package com.ordertracker.persistent.document;


import com.ordertracker.persistent.dictionary.Currency;
import com.ordertracker.persistent.document.template.SimpleDocumentTemplate;

import javax.persistence.*;
import java.math.BigDecimal;

/**
 * Description of class.
 * Created 2/11/13 12:56 PM
 *
 * @author andrey.rodin@playtech.com
 */

@Entity
@Table(name = "payment_order")
public class PaymentOrder extends SimpleDocumentTemplate {

    private static final long serialVersionUID = -4757164579421430738L;

    @ManyToOne(optional = false)
    private Currency currency;

    @Column(columnDefinition = "DECIMAL(10,5)")
    private BigDecimal currencyRate;

    @Column(length = 16, scale = 2, nullable = false)
    private BigDecimal sum;

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    public BigDecimal getCurrencyRate() {
        return currencyRate;
    }

    public void setCurrencyRate(BigDecimal currencyRate) {
        this.currencyRate = currencyRate;
    }

    public BigDecimal getSum() {
        return sum;
    }

    public void setSum(BigDecimal sum) {
        this.sum = sum;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof PaymentOrder)) return false;
        if (!super.equals(o)) return false;

        PaymentOrder that = (PaymentOrder) o;

        if (!currency.equals(that.currency)) return false;
        if (!currencyRate.equals(that.currencyRate)) return false;
        if (!sum.equals(that.sum)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + currency.hashCode();
        result = 31 * result + currencyRate.hashCode();
        result = 31 * result + sum.hashCode();
        return result;
    }

    @Override
    public String toString() {
        return "PaymentOrder{" +
                "currency=" + currency +
                ", currencyRate=" + currencyRate +
                ", sum=" + sum +
                " " + super.toString();
    }
}
